﻿using System;

namespace Library.UserInterface.Controls
{
    public class DateTime : Date
    {
        private Time _time;

        [Obsolete("Bu kontrolde Text özelliği yerine Value özelliği kullanılmalıdır.")]
        public override string Text
        {
            get
            {
                return base.Text;
            }
            set
            {
                base.Text = value;
            }
        }

        public string Value
        {
            get { return (base.Text + " " + _time.Text).Trim(); }
            set
            {
                if (value.Contains(" "))
                {
                    string[] parts = value.Split(' ');
                    base.Text = parts[0].Trim();
                    if (parts[1].Length > 4)
                        parts[1] = parts[1].Substring(0, 5);
                    _time.Text = parts[1];
                }
                else
                {
                    base.Text = value.Split(' ')[0];
                    _time.Text = "";
                }
            }
        }        

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            _time = new Time();
            _time.ID = ID + "_time";
            _time.Validate = Validate;
            _time.ValidationName = ValidationName + " - Saat";
            Controls.Add(_time);
        }

        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            base.Render(writer);
            //base.Text = base.Text.Split(' ')[0];
            _time.RenderControl(writer);
        }
    }
}